package edu.mis.modules.customer;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

public class CustomerValidator extends Validator {

	@Override
	protected void validate(Controller c) {
		validateString("customer.name", 1, 30, "name-error", "不能为空");
		validateRegex("customer.sex", "^male$|^female$", "sex-error", "不能为空");
		if(c.getPara("customer.email").length() > 0) {
			validateString("customer.email", 1, 30, "email-error", "长度超出限制");
			validateEmail("customer.email", "email-error", "格式不正确");
		}
		validateString("customer.phone", 1, 20, "phone-error", "长度超出限制");
	}

	@Override
	protected void handleError(Controller c) {
		c.setAttr("result", false);
		c.renderJson();
	}

}
